<?php

use think\facade\Config;
use think\migration\Migrator;

class ExamRecord extends Migrator
{
    public function change()
    {
        $table = $this->table('exam_record', [
            'engine' => 'InnoDB',
            'comment' => '考试记录',
            'collation' => 'utf8mb4_general_ci'
        ]);

        //删除表
        if ($table->exists()) {
            $dbPrefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
            $tableName = $table->getName();
            \think\facade\Db::execute('drop table if exists ' . $dbPrefix . $tableName);
//            $table->drop(); // 为什么不用这个方法来删除表，因为在我使用thinkphp6时，think-migrate的composer包并没有对这个方法进行具体实现，所以不能删除表
        }

        $table
            ->addColumn('exam_id', 'integer', ['limit' => 11, 'null' => 0, 'default' => '0','comment' => '考试id'])
			->addColumn('papers_id', 'integer', ['limit' => 11, 'null' => 0, 'default' => '0','comment' => '试卷id'])
			->addColumn('student_id', 'integer', ['limit' => 11, 'null' => 0, 'default' => '0','comment' => '考生id'])
			->addColumn('question_id', 'integer', ['limit' => 11, 'null' => 0, 'default' => '0','comment' => '试题id'])
			->addColumn('answer', 'string', ['limit' => 5120, 'null' => 0, 'default' => '','comment' => '答案'])
			->addColumn('type', 'boolean', ['limit' => 1, 'null' => 0, 'default' => '1','comment' => '类型 1考试 2练习.1=考试,2=练习,默认:1'])
			->addColumn('create_time', 'datetime', ['null' => 1, 'comment' => '创建时间'])
			->addColumn('update_time', 'datetime', ['null' => 1, 'comment' => '更新时间'])
			->addColumn('is_right', 'boolean', ['limit' => 1, 'null' => 0, 'default' => '0','comment' => '是否正确.1=正确,0=错误,默认:1'])
			->addColumn('score', 'boolean', ['limit' => 11, 'null' => 0, 'default' => '0','comment' => '分数'])
			
        ;

        $table->create();
    }
}